﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SeriesManager.DataLayer;
using System.IO;
using System.Collections.Generic;
using SeriesManager.Model;

namespace SeriesManager.Test.DataLayer
{
	[TestClass]
	public class FileManagerTests
	{
		const string TestSeriesPath = @"J:\Downloads\Serien\CastleTest\Data";

		#region GetFiles tests

		[TestMethod]
		public void GetFilesSuccessfull()
		{
			Type targetTyp = typeof(FileManager);
			var methode = targetTyp.GetMethod("GetFiles", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
			List<FileInfo> actual = (List<FileInfo>)methode.Invoke(FileManager.Instance, new object[] { TestSeriesPath });

			Assert.AreEqual(6, actual.Count);
			Assert.IsTrue(actual.Any(x => x.Name == "tvr-castle-s03e01-720p.mkv"));
			Assert.IsTrue(actual.Any(x => x.Name == "Castle.S04E01.Neuanfang.German.DL.DD51.Dubbed.720p.WEB-DL.h264-GDR.mkv"));
		}

		#endregion

		#region ExtractSeassonAndEpisode tests

		[TestMethod]
		public void ExtractSeassonAndEpisodeSuccessfullSingleDigits()
		{
			string name = "tvr-castle-s03e01-720p.mkv";
			int expectedSeaseon = 3;
			int expectedEpisode = 1;

			int actualSeasson = 0;
			int actualEpisode = 0;

			Type targetType = typeof(FileManager);
			var method = targetType.GetMethod("ExtractSeassonAndEpisode", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
			method.Invoke(FileManager.Instance, new object[] { name, actualSeasson, actualEpisode });
		}

		[TestMethod]
		public void ExtractSeassonAndEpisodeSuccessfullDoubleDigits()
		{
			string name = "tvr-castle-s23e51-720p.mkv";
			int expectedSeaseon = 23;
			int expectedEpisode = 51;


			int actualSeasson = 0;
			int actualEpisode = 0;

			Type targetType = typeof(FileManager);
			var method = targetType.GetMethod("ExtractSeassonAndEpisode", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
			method.Invoke(FileManager.Instance, new object[] { name, actualSeasson, actualEpisode });
		}

		#endregion

		[TestMethod]
		public void RenameFilesTest()
		{
			FileManager.Instance.RenameSeries(new Series(), TestSeriesPath);
		}
	}
}
